package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 移动端-套餐管理
 */
@RestController
@RequestMapping("/setmeal")
@Slf4j
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 查询所有套餐
     * @return
     */
    @PostMapping("/getSetmeal")
    public Result findAll(){
        log.info("查询所有套餐");
        List<Setmeal> setmeals = setmealService.findAll();
        return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,setmeals);
    }

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @PostMapping("/findById")
    public Result findById(Integer id){
        log.info("根据id查询套餐：{}", id);
        Setmeal setmeal = setmealService.finById(id);
        return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
    }
}
